﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business.DwzFrame;
using ZLCMS.Business;
using NHibernate;

namespace ZLCMS.Web.SystemManage.Basics.RightConfig.Role
{
    public partial class RoleDelete : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FrameHelper framePage = new FrameHelper(this);
            string ids = Request["ids"];
            if (!string.IsNullOrEmpty(ids))
            {
                string[] roleCodes = ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
                {
                    ITransaction tran = session.BeginTransaction();
                    try
                    {
                        session.CreateQuery("delete from UrRole where RoleCode in (:RoleCode)").SetParameterList("RoleCode", roleCodes).ExecuteUpdate();
                        session.CreateQuery("delete from UrUserRole where RoleCode in (:RoleCode)").SetParameterList("RoleCode", roleCodes).ExecuteUpdate();
                        session.CreateQuery("delete from UrRoleRight where RoleCode in (:RoleCode)").SetParameterList("RoleCode", roleCodes).ExecuteUpdate();
                        tran.Commit();
                        framePage.Alert(new ReturnCode() { statusCode = 200, message = "操作成功!", navTabId = framePage.NavTabId });
                    }
                    catch (System.Exception)
                    {
                        tran.Rollback();
                    }
                }
            }
            else
            {
                framePage.Alert(new ReturnCode() { statusCode = 300, message = "参数错误" });
            }
        }
    }
}
